/*
 * 1018_poj.cpp
 *
 *  Created on: 2012-5-16
 *      Author: jawinton
 */


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

#define MAX 110
#define CLR(arr,val) memset(arr,val,sizeof(arr))

struct Device
{
    int band;
    int price;
}dp[MAX][MAX];

bool cmp(const Device& d1,const Device& d2)
{
    return d1.band < d2.band || (d1.band==d2.band && d1.price < d2.price);
}

int main (void) {
	int Num[MAX], Cur[MAX];
	int cases;
	int n;
	cin >> cases;
	while (cases--) {
		int minBand = 0x7f7f7f7f, maxBand = 0x7f7f7f7f;
		cin >> n;
		for (int i = 0; i != n; i++) {
			cin >> Num[i];
			for (int j = 0; j < Num[i]; j++) {
				cin >> dp[i][j].band >> dp[i][j].price;
			}
			sort(dp[i], dp[i]+Num[i], cmp);
			minBand = min(minBand, dp[i][0].band);
			maxBand = min(maxBand, dp[i][Num[i]-1].band);
		}

		double ans = 0;
		int band, price;
		CLR(Cur,0);
		for (int cur = minBand; cur <= 	maxBand; cur = band + 1) {
			price = 0;
			band = 0x7f7f7f7f;
			for (int i=0; i<n; i++) {
				int j = 0; // int &j = Cur[i];	//动态规划的核心
				while (dp[i][j].band < cur) j++;
				for (int k = j; k != Num[i]; k++) {
					if (dp[i][k].price < dp[i][j].price) //possible bigger band, less price
						j = k;	//find the least price corporation which band is no smaller than cur
				}
				band = min(band, dp[i][j].band); //注意这里是min，不是max，思考为什么？
				price += dp[i][j].price;
			}
			ans = max(ans, (double)band/price);
		}
		printf("%.3f\n", ans);
	}
	return 0;
}
